using System;
using System.Collections.Generic;
using System.Text;
using KbWorksBlogMigrationtool.wss2007;
using System.Data;
using System.Net;
using System.Xml;
using System.Configuration;
namespace KbWorksBlogMigrationtool
{
    class ListProxy2007
    {
        Logging log = new Logging();
        AppSettingsReader conf = new AppSettingsReader();
        private string url = string.Empty;
        private string listName = string.Empty;

        public ListProxy2007(string Url, string ListName)
        {
            if (Url == String.Empty)
            {
                throw new ArgumentException("Parameter may not be String.Empty", "Url");
            }

            if (ListName == String.Empty)
            {
                throw new ArgumentException("Parameter may not be String.Empty", "ListName");
            }

            url = Url + "/_vti_bin/Lists.asmx";
            listName = ListName;
        }

        public XmlNodeList GetListDefinition()
        {
            //Create a reference to the web service and set some properties
            KbWorksBlogMigrationtool.wss2007.Lists Lists = new KbWorksBlogMigrationtool.wss2007.Lists();
            Lists.Url = url;
            Lists.Credentials =
                new NetworkCredential(Convert.ToString(conf.GetValue("networkuser", typeof(string))),
                 Convert.ToString(conf.GetValue("networkpass", typeof(string))),
                 Convert.ToString(conf.GetValue("domain", typeof(string))));
            
            //Get the data from the list
            XmlNode listDefinition = null;
            try
            {
                listDefinition = Lists.GetList(listName);
            }
            catch (Exception ex)
            {
                log.append(
               String.Format("Unable to query ListDefinition {0} of {1} exeptie {2}", listName, url, ex.ToString()), 4, "Error");
            }
            finally
            {
                Lists.Dispose();
            }
            XmlNodeList list = null;
            //DataSet ds = new DataSet();
            try
            {
                 list = Util.RunXPathQuery(listDefinition,"//sp:Field");
                
                return list;
            }
            catch (Exception ex)
            {
                log.append(
                    String.Format("Unable to query ListDefinition {0} of {1} exeptie {2}", listName, url,ex.ToString()), 4,"Error");
            }
            return list;

        }
        


    }
}
